$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'capital/remittancemerchants/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true },
			{ label: '门店ID', name: 'merchantsId', index: 'merchants_id', width: 80 }, 			
			{ label: '工厂id', name: 'factoryId', index: 'factory_id', width: 80 }, 			
			{ label: '业务参考号', name: 'businessNo', index: 'business_no', width: 80 }, 			
			{ label: '收款人编号', name: 'receiverNo', index: 'receiver_no', width: 80 }, 			
			{ label: '收款人账号', name: 'receiverAccount', index: 'receiver_account', width: 80 }, 			
			{ label: '收款人名称', name: 'receiverName', index: 'receiver_name', width: 80 }, 			
			{ label: '收方开户支行', name: 'receiverAccountBranch', index: 'receiver_account_branch', width: 80 }, 			
			{ label: '收款人所在省', name: 'receiverProvince', index: 'receiver_province', width: 80 }, 			
			{ label: '收款人所在市', name: 'receiverCity', index: 'receiver_city', width: 80 }, 			
			{ label: '收方邮件地址', name: 'receiverEmail', index: 'receiver_email', width: 80 }, 			
			{ label: '收方移动电话', name: 'receiverMobile', index: 'receiver_mobile', width: 80 }, 			
			{ label: '币种', name: 'currency', index: 'currency', width: 80 }, 			
			{ label: '付款分行', name: 'paymentBranch', index: 'payment_branch', width: 80 }, 			
			{ label: '结算方式', name: 'paymentType', index: 'payment_type', width: 80 }, 			
			{ label: '业务种类', name: 'businessType', index: 'business_type', width: 80 }, 			
			{ label: '付方账号', name: 'payerAccount', index: 'payer_account', width: 80 }, 			
			{ label: '期望日', name: 'expectDay', index: 'expect_day', width: 80 }, 			
			{ label: '期望时间', name: 'expectTime', index: 'expect_time', width: 80 }, 			
			{ label: '用途', name: 'useRemark', index: 'use_remark', width: 80 }, 			
			{ label: '金额', name: 'amount', index: 'amount', width: 80 }, 			
			{ label: '收方行号', name: 'receiverAccountNumber', index: 'receiver_account_number', width: 80 }, 			
			{ label: '收方开户银行', name: 'receiverAccountName', index: 'receiver_account_name', width: 80 }, 			
			{ label: '业务摘要', name: 'businessDigest', index: 'business_digest', width: 80 }, 			
			{ label: '创建时间', name: 'createTime', index: 'create_time', width: 80 }, 			
			{ label: '0:有效  1：失效', name: 'disabled', index: 'disabled', width: 80 }, 			
			{ label: '证件类型  1:身份证号码', name: 'credentialType', index: 'credential_type', width: 80 }, 			
			{ label: '证件号码', name: 'receiverCredential', index: 'receiver_credential', width: 80 }, 			
			{ label: '银行账户属性 0：对私，1：对公', name: 'receiverBankAccountPro', index: 'receiver_bank_account_pro', width: 80 }, 			
			{ label: '收款方账户的发卡行', name: 'receiverGateId', index: 'receiver_gate_id', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		remittanceMerchants: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.remittanceMerchants = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.remittanceMerchants.id == null ? "capital/remittancemerchants/save" : "capital/remittancemerchants/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.remittanceMerchants),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "capital/remittancemerchants/delete",
                    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get(baseURL + "capital/remittancemerchants/info/"+id, function(r){
                vm.remittanceMerchants = r.remittanceMerchants;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});